package com.example.administrator.damaiwang.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.damaiwang.R;
import com.example.administrator.damaiwang.bean.AllContent;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2016/12/12.
 */

public class YanChuAdapter extends BaseAdapter {
    private String BASR_URL1 = "http://pimg.damai.cn/perform/project/";
    private List<AllContent> mList;

   public void setData(List<AllContent> list){

        this.mList=list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList!=null?mList.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mList!=null?mList.get(i):null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.allcontent_item,viewGroup,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
        AllContent content = mList.get(i);
        holder.tv_name.setText(content.getName());
        holder.tv_price.setText(content.getPrice());
        holder.tv_time.setText(content.getTime());
        holder.tv_VenName.setText(content.getVenName());
        //TODO 下载图片
        String imageId = content.getImageId();
        String imageURI = BASR_URL1 + imageId.substring(0,4) +"/"+imageId+"_n.jpg";
       Picasso.with(viewGroup.getContext()).load(imageURI).into(holder.iv_allcontent);
        return convertView;
    }
    static class ViewHolder {
    private TextView tv_name,tv_time,tv_VenName,tv_price;
        private ImageView iv_allcontent;
        ViewHolder(View view){
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
            tv_VenName = (TextView) view.findViewById(R.id.tv_VenName);
            tv_price = (TextView) view.findViewById(R.id.tv_price);
            iv_allcontent= (ImageView) view.findViewById(R.id.iv_allcontent);
        }
    }
}
